package a2023.a1018;

import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.TreeSet;
import java.util.stream.Collectors;

/**
 * @author lenovo
 * @date 2023/10/18
 */
public class a {
    public static void main(String[] args) {
        System.out.println(maxKelements(new int[]{1, 10, 3, 3, 3},
                3));
    }

    public static long maxKelements(int[] nums, int k) {
        PriorityQueue<Integer> q = new PriorityQueue<Integer>((a, b) -> b - a);
        for (int num : nums) {
            q.offer(num);
        }
        long ans = 0;
        for (int i = 0; i < k; ++i) {
            int x = q.poll();
            ans += x;
            q.offer((x + 2) / 3);
        }
        return ans;
    }
}
